<?php

class Register_new_user_model extends CI_Model{
    
    
    function __construct()
    {
        parent::__construct();
    }
    
    
    public function commit_new_user() {
        
        //$user = new Entities\User;
        $newuser = new ORM\Dynasties2\Users;
        $newuser->setFirstName($this->input->post('firstname'));
        $newuser->setLastname($this->input->post('lastname'));
        
        $salt = 'LMs_bo9-14_f';
        $salted_password = $salt . $this->input->post('password');
        
        $encrypted_password = md5($salted_password);
        $this->load->library('encrypt');
        $double_encrypted_password = $this->encrypt->encode($encrypted_password);
        
        $newuser->setPassword($double_encrypted_password);
        
        $newuser->setEmail($this->input->post('email'));
        $newuser->setCreated(new DateTime());
        $newuser->setReferral($this->input->post('referral'));
        //$newuser->setOriginal_IP($_SERVER['REMOTE_ADDR']);
        $newuser->setOriginalIP($this->input->ip_address());
        $newuser->setLastIP($this->input->ip_address());
        $newuser->setIsActive('1');
        $newuser->setLastOn(new DateTime());
        $newuser->setOkToEmail('1');
        
        

        // standard way in CodeIgniter to access a library in a controller: $this->library_name->member->memberFunction()
        // save the object to database, so that it can obtain its ID
        $this->doctrine->em->persist($newuser);

        $this->doctrine->em->flush();
        
        //echo $newuser->getID();
        
        $this->load->view('register_success_view');
        
    
    }
    }